<template>
  <div class="address1">
    <div class="header">
      <van-nav-bar
        title="确认订单"
        left-text="返回"
        left-arrow
        @click-left="$router.back()"
      />
    </div>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import Vue from 'vue'
import { AddressEdit, Toast, NavBar } from 'vant'
import { areaList } from '@vant/area-data'
import { inputAddress } from '@/api/order'

Vue.use(AddressEdit)
Vue.use(Toast)
Vue.use(NavBar)
export default {
  data () {
    return {
      areaList,
      searchResult: []
    }
  },
  methods: {
    onSave (content) {
      Toast('save')
      inputAddress({
        userid: localStorage.getItem('userid'),
        name: content.name,
        tel: content.tel,
        province: content.province,
        city: content.city,
        county: content.county,
        addressDetail: content.addressDetail,
        isDefault: content.isDefault
      }).then(res => {
        console.log(res.data)
        this.$router.back()
      })
      console.log(content)
    },
    onDelete () {
      Toast('delete')
    },
    onChangeDetail (val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区'
          }
        ]
      } else {
        this.searchResult = []
      }
    }
  }
}
</script>
